using UnityEngine;
using System;
using Entities;
using System.Collections.Generic;

public class SpawnMobGroup : MonoBehaviour {
	
	public MobGroup mobGroup;
	
	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnTriggerEnter(Collider other){
		if (other.gameObject.tag == "Player" && !mobGroup.spawned){
			int i = 0;
			List<Mob> mobs = mobGroup.getMobs();
			foreach(Mob mob in mobs){
				if (mobs.Count > 1) {
					double alpha = (i * 360/(mobs.Count - 1))* Math.PI/180;
					Vector3 pos = new Vector3(transform.position.x + 4 * (float) Math.Cos(alpha),transform.position.y + 3, transform.position.z + 4 * (float)Math.Sin(alpha));
					
					if (i == mobs.Count - 1) pos = new Vector3(transform.position.x,transform.position.y + 3, transform.position.z);
					mob.setGameObject((GameObject)Instantiate(mob.getPrefab(), pos, new Quaternion()));
					Mobs.Instance.addMob(mob);
					i++;
				}
			}
			mobGroup.spawned = true;
		}
	}
}
